<?php include('navigation.php'); ?>
<script src="javascripts/dataTables/jquery.jeditable.js" type="text/javascript"></script>
<?php
$pplconfc = new M('paipaile_config');
$pplconf = $pplconfc->find();
// echo var_export($pplconf);
?>
<script>
    $(function () {
        $('.conf-ppl').on('switch-change', function (e, data) {
            var $el = $(data.el), value = data.value;
            if (value) {
                $.get("paipaile.do.php", {do: "confswitch", switchname: $el[0].name, cid: "1"}, function () {
                });
            } else {
                $.get("paipaile.do.php", {do: "confswitch", switchname: $el[0].name, cid: "0"}, function () {
                });
            }
        });
        $('#pplzjvote').dataTable({'iDisplayLength':<?php echo $pplconf['pplvotenum'];?>});
        $('#pplzjchoujiang').dataTable({'iDisplayLength': 10});
        var oTable = $('#ppltable').dataTable({'iDisplayLength': 20});
        oTable.$('.edit').editable('paipaile.do.php?do=edit', {
            "noeditcol": [0],
            "indicator": '保存中...',
            "placeholder": '此空暂无信息',
            "callback": function (sValue, y) {
                var aPos = oTable.fnGetPosition(this);
                oTable.fnUpdate(sValue, aPos[0], aPos[1]);
            },
            "submitdata": function (value, settings) {
                var id = $(this).parent().attr('id');
                var name = $(this).attr('name');
                return {
                    "cid": id,
                    "name": name
                };
            },
            "width": "90%",
            "height": "100%"
        });
    });
</script>
<link href="../files/css/semantic.min.css" media="all" rel="stylesheet" type="text/css"/>
<style>
    .control-label {
        text-align: right;
    }
</style>
<!-- End Navigation -->
<div class="modal fade" id="pplmodal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" class="close" data-dismiss="modal" type="button">&times;</button>
                <h4 class="modal-title">
                    拍拍乐相关参数设置
                </h4>
            </div>
            <div class="modal-body">
                <center><a href="index.php"><img width="200" height="70" src="images/logo-login%402x.png"/></a></center>
                <p>
                </p>

                <div class="alert alert-warning">
                    <button class="close" data-dismiss="alert" type="button">×</button>
                    如需设置背景，标头图片，请在paipaile/images/下手动替换，尽量不要修改图片的尺寸。<br>
                </div>
                <div class="form-group row">
                    <label class="control-label col-md-4">上传照片数量:</label>

                    <div class="col-md-8">
                        <form action="paipaile.do.php?do=changeconfig&cof=pplvotenum" method="post">
                            <div class="input-group">
                                <input class="form-control" value="<?php echo $pplconf['pplvotenum']; ?>" name="name"
                                       type="text"/><span class="input-group-btn"><button class="btn btn-success"
                                                                                          type="submit">修改
                                    </button></span>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="control-label col-md-4">拍拍乐用户可投票数:</label>

                    <div class="col-md-8">
                        <form action="paipaile.do.php?do=changeconfig&cof=pplvotecannum" method="post">
                            <div class="input-group">
                                <input class="form-control" value="<?php echo $pplconf['pplvotecannum']; ?>" name="name"
                                       type="text"/><span class="input-group-btn"><button class="btn btn-success"
                                                                                          type="submit">修改
                                    </button></span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="form-group row">
                <label class="control-label col-md-4">拍拍乐规则描述:</label>

                <div class="col-md-8">
                    <form action="paipaile.do.php?do=changeconfig&cof=rule" method="post">
                        <div class="input-group">
                            <input class="form-control" value="<?php echo $pplconf['rule']; ?>" name="name"
                                   type="text"/><span class="input-group-btn"><button class="btn btn-success"
                                                                                      type="submit">修改
                                </button></span>
                        </div>
                    </form>
                </div>
            </div>
            <div class="form-group row">
                <label class="control-label col-md-5">达到上传照片数量才可以投票:</label>

                <div class="col-md-7">
                    <div class="toggle-switch conf-ppl" data-off="danger" data-on="success" style="margin-bottom:8px">
                        <input <?php if ($pplconf['must_switch']) {
                            echo "checked";
                        } ?> name="must_switch" type="checkbox">
                    </div>
                </div>
            </div>
            <div class="form-group row">
                <label class="control-label col-md-5">已经中奖用户不可参与游戏:</label>

                <div class="col-md-7">
                    <div class="toggle-switch conf-ppl" data-off="danger" data-on="success" style="margin-bottom:8px">
                        <input <?php if ($pplconf['black_switch']) {
                            echo "checked";
                        } ?> name="black_switch" type="checkbox">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default-outline" data-dismiss="modal" type="button">关闭</button>
            </div>
        </div>
    </div>
</div>
<div class="main-content">
    <!-- DataTables Example -->
    <div class="row">
        <div class="col-lg-12">
            <div class="widget-container fluid-height clearfix">
                <div class="heading">
                    <?php
                    $zjuserc = new M("paipaile_zjuser");
                    $paipaile_m = new M("paipaile");
                    $querytp = $paipaile_m->select('1');
                    // echo var_export($querytp);
                    // $toupiao="SELECT * FROM  `weixin_paipaile`";
                    //$querytp=mysql_query($toupiao,$link) or die(mysql_error());
                    //$numdel = mysql_num_rows($querytp);
                    $numdel = count($toupiao);
                    ?>
                    <i class="icon-table"></i>拍拍乐管理<a class="ui red  tag label">当前为第<?php echo $pplconf['pplround']; ?>
                        轮</a>
                    <a class="btn btn-sm btn-primary-outline pull-right" data-toggle="modal" href="#pplmodal"><i
                            class="icon-gear"></i>拍拍乐参数设置</a>
                    <a class="btn btn-sm btn-primary-outline pull-right poppub" href="paipaile.do.php?do=chongzhi"
                       id="tooltip-top" data-toggle="tooltip" title="此操作将删除所有拍拍乐用户数据，但不会影响中奖纪录，也不会影响当前轮数。"><i
                            class="icon-ban-circle"></i>拍拍乐游戏重置</a>
                </div>
                <div class="alert alert-warning">
                    <button class="close" data-dismiss="alert" type="button">×</button>
                    注意： 　1、可以点击右上角设置拍拍乐的相关参数。
                    <br>
                    　　　　2、这里是查看游戏中的用户和投票信息，结束后还会有纪录在本页的最下方显示。
                    <br>
                    规则：在开启本模块后，微信墙系统中会多出一个拍拍乐的功能回复，用户回复拍拍乐后，可进入拍拍乐系统，等待主持人开始游戏后，用户发送照片，前
                    <?php echo $pplconf['pplvotenum']; ?>
                    位发送的照片将会被系统记录，并生成一个网页用户可以参与进行投票，大屏幕会显示当前选手的票数。<br>
                </div>
                <div class="widget-content padded clearfix">
                    <table class="table table-bordered table-striped" id="ppltable">
                        <thead>
                        <th>
                            序号
                        </th>
                        <th>
                            昵称
                        </th>
                        <th class="hidden-xs">
                            图片
                        </th>
                        <th>
                            票数
                        </th>
                        </thead>
                        <tbody>
                        <?php
                        include('biaoqing.php');
                        for ($i = 0, $l = count($querytp); $i < $l; $i++) {
                            $q = $querytp[$i];
                            $q['nickname'] = pack('H*', $q['nickname']);
                            $q = emoji_unified_to_html(emoji_softbank_to_unified($q));
                            ?>
                            <tr id='<?php echo $q['id']; ?>
						'>
                                <td class='edit' name='id'>
                                    <?php echo $q['id']; ?>
                                </td>
                                <td>
                                    <img class="ui avatar image"
                                         src="<?php echo $q['avatar']; ?>"><?php echo $q['nickname']; ?>
                                </td>
                                <td>
                                    <img class="rounded small ui image" src="<?php echo $q['picurl']; ?>">
                                </td>
                                <td class="hidden-xs edit" name='voteres'>
                                    <?php echo $q['voteres']; ?>
                                </td>
                            </tr>
                            <?php
                        } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!-- end DataTables Example -->
    <!-- DataTables Example -->
    <div class="row">
        <div class="col-lg-12">
            <div class="widget-container fluid-height clearfix">
                <div class="heading">
                    <i class="icon-table"></i>拍拍乐中奖纪录管理
                    <a class="btn btn-sm btn-primary-outline pull-right" href="paipaile.do.php?do=clearzjunfo"><i
                            class="icon-refresh"></i>中奖池清除</a>
                </div>
                <div class="widget-content padded clearfix">
                    <!--第一个 -->
                    <div class="ui segment">
                        <div class="heading">
                            <i class="icon-signal"></i>投票纪录管理
                        </div>
                        <table class="table table-striped" id="pplzjvote">
                            <thead>
                            <th>
                                序号
                            </th>
                            <th>
                                昵称
                            </th>
                            <th class="hidden-xs">
                                图片
                            </th>
                            <th class="hidden-xs">
                                票数
                            </th>
                            <th>
                                状态
                            </th>
                            <th>
                                轮数
                            </th>
                            <th>
                                操作
                            </th>
                            </thead>
                            <tbody>
                            <?php
                            $zjuser_vote = $zjuserc->select("`zjtype`='2'");
                            foreach ($zjuser_vote as $q) {
                                $q['nickname'] = pack('H*', $q['nickname']);
                                $q = emoji_unified_to_html(emoji_softbank_to_unified($q));
                                ?>
                                <tr id='<?php echo $q['id']; ?>
								'>
                                    <td class='edit' name='id'>
                                        <?php echo $q['id']; ?>
                                    </td>
                                    <td>
                                        <img class="ui avatar image"
                                             src="../wall/images/ico-<?php echo $q['fromtype']; ?>.png"><img
                                            class="ui avatar image"
                                            src="<?php echo $q['avatar']; ?>"><?php echo $q['nickname']; ?>
                                    </td>
                                    <td>
                                        <img class="rounded small ui image" src="<?= $q['picurl'] ?>">
                                    </td>
                                    <td class="hidden-xs edit" name='voteres'>
                                        <<?php echo $q['voteres']; ?>
                                    </td>
                                    <td>
                                        <?php
                                        if ($q['status']) {
                                            echo '<span class="label label-success">已发</span>';
                                        } else {
                                            echo '
									<span class="label label-warning">待办</span>';
                                        }
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                        $color = array('success', 'warning', 'primary');
                                        $cnum = $q['round'] % 3;
                                        echo '<span class="label label-' . $color[$cnum] . '">
									第' . $q['round'] . '轮</span>';
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                        if (!$q['status']) {
                                            echo "<a href='paipaile.do.php?do=cj_award&cid=" . $q['id'] . "'>发奖</a>";
                                        } else {
                                            echo '<span class="label label-success">已发</span>';
                                        }

                                        ?>
                                    </td>
                                </tr>
                                <?php $i++;
                            } ?>
                            </tbody>
                        </table>
                    </div>
                    <!--第二个-->
                    <div class="ui segment">
                        <div class="heading">
                            <i class="icon-gift"></i>抽奖纪录管理
                        </div>
                        <table class="table table-striped" id="pplzjchoujiang">
                            <thead>
                            <th>
                                序号
                            </th>
                            <th>
                                昵称
                            </th>
                            <th>
                                状态
                            </th>
                            <th>
                                轮数
                            </th>
                            <th>
                                操作
                            </th>
                            </thead>
                            <tbody>
                            <?php
                            $zjuser_cj = $zjuserc->select("`zjtype`='1'");
                            //					echo var_export($zjuser_cj);
                            foreach ($zjuser_cj as $q) {
                                $q['nickname'] = pack('H*', $q['nickname']);
                                $q = emoji_unified_to_html(emoji_softbank_to_unified($q));
                                ?>
                                <tr id='<?php echo $q['id']; ?>'>
                                    <td class='edit' name='id'>
                                        <?php echo $q['id']; ?>
                                    </td>
                                    <td>
                                        <img class="ui avatar image"
                                             src="../wall/images/ico-<?php echo $q['fromtype']; ?>.png"><img
                                            class="ui avatar image"
                                            src="<?php echo $q['avatar']; ?>"><?php echo $q['nickname']; ?>
                                    </td>
                                    <td>
                                        <?php
                                        if ($q['status']) {
                                            echo '<span class="label label-success">已发</span>';
                                        } else {
                                            echo '
									<span class="label label-warning">待办</span>';
                                        }
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                        $color = array('success', 'warning', 'primary');
                                        $cnum = $q['round'] % 3;
                                        echo '<span class="label label-' . $color[$cnum] . '">
									第' . $q['round'] . '轮</span>';
                                        ?>
                                    </td>
                                    <td>
                                        <?php
                                        if (!$q['status']) {
                                            echo "<a href='paipaile.do.php?do=cj_award&cid=" . $q['id'] . "'>发奖</a>";
                                        } else {
                                            echo '<span class="label label-success">已发</span>';
                                        }

                                        ?>
                                    </td>
                                </tr>
                                <?php $i++;
                            } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- end DataTables Example -->
</div>
</body>
</html>